package com.leoman.customer.service.impl;

import com.leoman.common.core.Result;
import com.leoman.common.service.impl.GenericManagerImpl;
import com.leoman.customer.dao.CustomerDao;
import com.leoman.customer.dao.CustomerDemandDao;
import com.leoman.customer.entity.Customer;
import com.leoman.customer.entity.CustomerDemand;
import com.leoman.customer.service.CustomerDemandService;
import com.leoman.customer.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Daisy on 2016/12/27.
 */
@Service
public class CustomerDemandServiceImpl extends GenericManagerImpl<CustomerDemand,CustomerDemandDao> implements CustomerDemandService {

    @Autowired
    private CustomerDemandDao customerDemandDao;

    /**
     * 保存
     * @return
     */
    @Override
    @Transactional
    public Result saveCustomerDemand(CustomerDemand customerDemand){

        customerDemandDao.save(customerDemand);
        return Result.success();
    }

    @Override
    public List<CustomerDemand> findByCustomerId(Long customerId) {
        return customerDemandDao.findByCustomerId(customerId);
    }

/*    @Override
    public Page<CustomerDemand> findTodayDemands(Long adminId){
        String sql = "SELECT \n" +
                "  cd.* \n" +
                "FROM\n" +
                "  t_customer_demand cd \n" +
                "  LEFT JOIN t_customer c \n" +
                "    ON c.`id` = cd.`customer_id` \n" +
                "WHERE c.`status` = 0 \n" +
                "  AND DATE(\n" +
                "    FROM_UNIXTIME(cd.`next_time` / 1000)\n" +
                "  ) = CURDATE() \n" +
                "  AND c.`admin_id` = "+adminId;
        Page<CustomerDemand> list = queryBySql(sql, CustomerDemand.class);
        return list;
    }*/

}
